<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" >
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      @keydown.enter="newTask"
      autofocus
    />
  </header>
</template>

<script>  
export default {
  data() {
    return {
      task:''
    }
  },
  computed: {

  },
  methods: {
    newTask(e) {
      if (e.target.value.length === 0) {
        alert("任务名不能为空");
        return
      }
      let id = this.$store.state.todolist.length === 0 ? 100 : this.$store.state.todolist[this.$store.state.todolist.length - 1].id + 1
      const newtodolist= ({
        id: id,
        name: e.target.value,
        isDone: false
      })
      this.$store.commit("addtodolist", newtodolist)
      e.target.value=''
    }
  }
}
</script>